package com.fzy.core.system.action;

import ge.core.system.entity.Mapping;
import ge.core.system.entity.Module;
import ge.core.system.entity.Property;

import java.util.Date;

import com.fzy.core.system.service.DbService;
import com.fzy.core.utils.U;
import com.fzy.core.webwork.BaseAction;
import com.fzy.core.webwork.MyValidationAware;
import com.opensymphony.xwork.ModelDriven;
import com.opensymphony.xwork.Preparable;

public class PropertySaveAction extends BaseAction implements Preparable, MyValidationAware, ModelDriven {

	private static final long serialVersionUID = -55725527522956019L;
	
	String errorDispatch;
	Property property;
	DbService dbService;

	public void prepare() throws Exception {
		errorDispatch = "dispatcher:/pages/refresh-parent.jsp";
		property = (Property)validateIdAndGetEntity(request.getParameter("id"), Property.class);
        
		// default values
        if(property == null){
        	property = new Property();
        	property.setIsKey("0");
        	property.setIsNotNull("0");
        	property.setIsQuery("0");
        	property.setIsShow("1");
        	property.setIsUnique("0");
        	property.setIsWork("1");
        	property.setPropertyType("string");
        }
	}

	public void validate() {

	}

	public String execute() throws Exception {
		dbService.saveEntityId(property);

		addActionMessage(getText("success.save"));
		return "dispatcher:/pages/refresh-parent.jsp";
	}

	public Object getModel() {
		return property;
	}

	public String getErrorDispatch() {
		return errorDispatch;
	}

	public void setDbService(DbService dbService) {
		this.dbService = dbService;
	}

}
